/**
 * 自定义验证规则
 * @param  {[any]} filed 需要验证的值
 * @param  {[string]} rule  验证规则 如max:30, required等
 * @return {[bool]}         验证是否通过
 */
function validator(filed, rule) {
  const item = rule.split(':')
  const ruleKey = item[0]
  const ruleContent = item[1]

  switch (ruleKey) {
    case 'require':
      return !!filed

    case 'max':
      return filed.length <= ruleContent

    case 'min':
      return filed.length >= ruleContent

    default:
      return true
  }
}

export default validator
